package com.wan.tool;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.Calendar;

public class Saying {

	public String en;
	public String cn;

	public Saying(String en, String cn) {
		this.en = en;
		this.cn = cn;
	}

    public static Saying getOneSaying() {
        Saying saying = null;
        Calendar c = Calendar.getInstance();
        int day = c.get(Calendar.DATE);
        day = day % 31 + 1;
        SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(DBManage.DB_PATH + "/" + DBManage.DB_NAME, null);
        String sql = "select en , cn  from daysay where id = " + day;
        Cursor cursor = database.rawQuery(sql, null);
        if (cursor != null) {
            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                String en = cursor.getString(cursor.getColumnIndex("en"));
                String cn = cursor.getString(cursor.getColumnIndex("cn"));
                saying = new Saying(en, cn);
                cursor.moveToNext();
            }
            cursor.close();
        }
        database.close();
        return saying;
    }

}
